package com.xxxx.mytest.maps

/**
 * 相比集合更复杂
 */
object MapTests {
  def main(args: Array[String]): Unit = {

    /**
     * 创建
     */
    val map: Map[String, Any] = Map("name" -> "zhangsan", "age" -> 18, ("money", 200))
    map.foreach(println)
    map.foreach(x => {
      println(x._1 + ":" + x._2)
    })

    val option: Option[Any] = map.get("name")
    println(option)
    println(option.get)
    val option1: Option[Any] = map.get("name2")
    println(option1)
    //    println(option1.get)
    //对none进行get会出现NoSuchElementException
    println(option1.getOrElse("没有"))

    val value: Any = map.getOrElse("age1", 100)
    println(value)

    //entry遍历

    val set: Set[String] = map.keySet

    set.foreach(x => {
      println(x + ":" + map.get(x).get)
    })

    val values: Iterable[Any] = map.values
    values.foreach(println)

    //以key为操作的核心点


  }

}
